package controllers;

import java.util.Date;

import models.DriverJourney;
import models.Journey;
import models.User;
import models.Vehicle;
import play.data.validation.Required;
import play.mvc.With;

import common.FBSecure;

@With(FBSecure.class)
public class StartJourneyInfo extends FBController {

	public static void startjourneyinfo(@Required String plate, @Required String departurestate,
			@Required String departuretownn, @Required String departurestreet, @Required Date departuredate,
			@Required String departurehour, @Required String arrivestate,
			@Required String arrivetownn, @Required String arrivestreet, String journeynotes,
			String expecteddistance, String expectedtime, @Required boolean priceshare,
			@Required Integer numberofhitchhiker){
		
		setFbIdandName();

		User user = getUser();
		
		if (user.getVehicles().isEmpty()){
			renderTemplate("Vehicles/vehicles.html", user);
		}
		
		if (validation.hasErrors()) {
			renderTemplate("StartJourneyInfo/startjourneyinfo.html", user);
		}
		
		Vehicle vehicle = user.findVehicle(plate);
		
		
        
		DriverJourney driverJourney = user.addStartJourney(user, vehicle, departurestate, departuretownn, departurestreet, departuredate, departurehour,
				arrivestate, arrivetownn, arrivestreet, journeynotes, expecteddistance, expectedtime, priceshare, numberofhitchhiker);

		String msg = "Seyahatiniz oluşturuldu!";
		
		renderTemplate("DriverJourneyDetails/driverjourneydetails.html", user, driverJourney, msg);	
	}
}
